package com.project.server.service.companies.impl;

import com.project.common.core.domain.BaseServer;
import com.project.server.domain.companies.TCompany;
import com.project.server.mapper.companies.TCompanyMapper;
import com.project.server.service.companies.ITCompanyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 企业信息Service业务层处理
 *
 * @author project
 */
@Service
public class TCompanyServiceImpl extends BaseServer implements ITCompanyService {

    private static final Logger log = LoggerFactory.getLogger(TCompanyServiceImpl.class);

    @Resource
    private TCompanyMapper tCompanyMapper;

    /**
     * 查询企业信息
     *
     * @param compId 企业信息ID
     * @return 企业信息
     */
    @Override
    public TCompany selectTCompanyById(Long compId) {
        return tCompanyMapper.selectTCompanyById(compId);
    }

    /**
     * 查询企业信息列表
     *
     * @param tCompany 企业信息
     * @return 企业信息
     */
    @Override
    public List<TCompany> selectTCompanyList(TCompany tCompany) {
        return tCompanyMapper.selectTCompanyList(tCompany);
    }

    /**
     *  查询所有企业列表
     *
     *  @return 企业信息
     */
    @Override
    public List<TCompany> selectTCompanyAll() {
        return tCompanyMapper.selectTCompanyAll();
    }

    /**
     * 根据员工id查询企业选择框列表
     *
     * @param staffId 员工ID
     * @return
     */
    @Override
    public List<Integer> selectTCompanyListByStaffId(Long staffId) {
        return tCompanyMapper.selectTCompanyListByStaffId(staffId);
    }

    /**
     * 根据报修记录id查询企业选择框列表
     *
     * @param serviceId 报修记录ID
     * @return
     */
    @Override
    public List<Integer> selectTCompanyByServiceId(Long serviceId) {
        return tCompanyMapper.selectTCompanyByServiceId(serviceId);
    }

    /**
     * 根据缴费记录id查询企业选择框列表
     *
     * @param payId 缴费记录id
     * @return
     */
    @Override
    public List<Integer> selectTCompanyByPayId(Long payId){
        return tCompanyMapper.selectTCompanyByPayId(payId);
    }

    /**
     * 新增企业信息
     *
     * @param tCompany 企业信息
     * @return 结果
     */
    @Override
    public int insertTCompany(TCompany tCompany) {
        TCompany tCompany1 = new TCompany();
        tCompany1.setCompName(tCompany.getCompName());
        tCompany1.setCompType(tCompany.getCompType());
        List<TCompany> companies = tCompanyMapper.selectTCompanyByCompName(tCompany1);
        if (companies.size() > 0) {
            return 0;
        }
        super.insert(tCompany);
        return tCompanyMapper.insertTCompany(tCompany);
    }

    /**
     * 修改企业信息
     *
     * @param tCompany 企业信息
     * @return 结果
     */
    @Override
    public int updateTCompany(TCompany tCompany) {
        super.update(tCompany);
        return tCompanyMapper.updateTCompany(tCompany);
    }

    /**
     * 批量删除企业信息
     *
     * @param compIds 需要删除的企业信息ID
     * @return 结果
     */
    @Override
    public int deleteTCompanyByIds(Long[] compIds) {
        return tCompanyMapper.deleteTCompanyByIds(compIds);
    }

    /**
     * 删除企业信息信息
     *
     * @param compId 企业信息ID
     * @return 结果
     */
    @Override
    public int deleteTCompanyById(Long compId) {
        return tCompanyMapper.deleteTCompanyById(compId);
    }
}
